class util {
  getPreUrl() {
    // 'http://10.10.10.107:8080/game-lobby'
    const onHttps = window.location.href.match(/https/)
    if (window.location.hostname.match(/10\.10\.10|localhost|192\.168/)) {
      console.log('localhost')
      return onHttps ? 'https://lefantian.jiahuagame.com/game-lobby' : 'http://lefantian.jiahuagame.com/game-lobby'
      // return onHttps ? 'https://lefantian-s.jiahuagame.com/game-lobby' : 'http://lefantian-s.jiahuagame.com/game-lobby'
      // return onHttps ? 'https://c-c.jiahuagame.com/game-lobby' : 'http://c-c.jiahuagame.com/game-lobby'
    } else if (window.location.hostname.match(/lefantian/)) {
      return onHttps ? 'https://lefantian.jiahuagame.com/game-lobby' : 'http://lefantian.jiahuagame.com/game-lobby'
    } else {
      return onHttps ? 'https://c-c.jiahuagame.com/game-lobby' : 'http://c-c.jiahuagame.com/game-lobby'
    }
  }

  getQueryString(name) {
    var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i')
    var r = window.location.search.substr(1).match(reg)
    if (r != null) {
      return unescape(r[2])
    }
    return null
  }

  getDateTime(unixTime) {
    let date = new Date(unixTime)
    if (Number.isNaN(date.getHours())) {
      date = new Date();
    }
    let hours = date.getHours()
    let formatedHours = hours >= 10 ? hours : '0' + hours
    let minutes = date.getMinutes()
    let formatedMinutes = minutes >= 10 ? minutes : '0' + minutes
    let seconds = date.getSeconds()
    let formatedSeconds = seconds >= 10 ? seconds : '0' + seconds
    console.log(unixTime);
    console.log(date);
    return `${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate()} ${formatedHours}:${formatedMinutes}:${formatedSeconds}`
  }
}

export default util